<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
    $(document).ready(function() {

        $("#kmlDocumentUpload").hide();

        var mode = document.getElementById("edit_mode").value;

        if (mode == 2) {
            var fieldIds = new Array('submitDate',
                    'contactPersonId',
                    'designationId',
                    'personMobileId',
                    'personLandPhoneId',
                    'personEmailId',
                    'personFaxId',
                /*'planNoId', 'lotNoId', 'hectareId', 'acreId', 'roodsId', 'perchesId'*/
                    'purposeId'
                    ,'alienationMethodId5',
                    'alienationMethodId6',
                    'gnDivisionId',
                    'districtId',
                    'dsDivisionId',
                    'attachDocBtn'/*,
                 'addChild'*/);
            enableFields(fieldIds);
            //$("#attachFile").hide();

        } else {

            var pls_enter_department_name = "<br>" + document.getElementById("pls_enter_department_name").value;
            var pls_enter_department_address = "<br>" + document.getElementById("pls_enter_department_address").value;
            var pls_enter_submit_date = "<br>" + document.getElementById("pls_enter_submit_date").value;
            var pls_enter_contact_person = "<br>" + document.getElementById("pls_enter_contact_person").value;
            var pls_select_gn_division = $("#pls_select_gnDivision").val();

            $("#gov-land-init-ReleseToDepartment-application-form").validate({
                rules: {
                    departmentNameId: {
                        required: true
                    },
                    submitDate:{
                        required:true
                    },
                    departmentAddressId:{
                        required:true
                    },
                    contactPersonId:{
                        required:true
                    },
                    gnDivisionId:{
                        selectBox:"default"
                    }
                },
                messages: {
                    departmentName: {
                        required:pls_enter_department_name
                    },
                    submitDate:{
                        required:pls_enter_submit_date
                    },
                    departmentAddress:{
                        required:pls_enter_department_address
                    },
                    contactPersonId:{
                        required:pls_enter_contact_person
                    },
                    gnDivisionId:{
                        selectBox:pls_select_gn_division
                    }
                }
            });

        }
        /* if (mode == 3 || mode == 4 || mode == 6) {
         showLandDetails();
         $('#landDetails').hide();
         }  */
    });

    function getDsDivisionByDistrict() {
        var oSelect = document.getElementById('districtId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() +'</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id:id,mode:2},
                         function(data) {
                             var ds = data.dsDivisionList;
                             for (var i = 0; i < ds.length; i++) {
                                 options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                             }
                             $("select#dsDivisionId").html(options1);
                             //$("select#gnDivisionId").html('<option value="0"> -- Select -- </option> ');
                             $("select#gnDivisionId").html('<option value="0">' + $('#select').val() + '</option> ');
                         });
            }
        }
    }

    function getGnDivisionByDsDivision() {
        var oSelect = document.getElementById('dsDivisionId');
        //var options1 = '<option value="0"> -- Select -- </option> ';
        var options1 = '<option value="0">' + $('#select').val() +'</option> ';
        for (var iCount = 0; oSelect.options[iCount]; iCount++) {
            if (oSelect.options[iCount].selected == true) {
                var id = oSelect.options[iCount].value;
                $.getJSON('${pageContext.request.contextPath}/common/DivisionLookupService', {id:id,mode:3},
                         function(data) {
                             var ds = data.gnDivisionList;
                             for (var i = 0; i < ds.length; i++) {
                                 options1 += '<option value="' + ds[i].optionValue + '">' + ds[i].optionDisplay + '</option>'
                             }
                             $("select#gnDivisionId").html(options1);
                         });
            }
        }
    }

</script>
<div id="land-registration-module-home-title" class="module-home-title">
    <s:if test="#session.userGroup !='slc'">
        <s:include value="../alienationApplicationNavigationDetail.jsp"/>
    </s:if>
    <%--<div id="back-button" align="right">
        &lt;%&ndash; <s:submit type="input" value="%{getText('back.label')}" onclick="goBack();"/>&ndash;%&gt;
        <s:submit type="input" value="%{getText('print.label')}" onclick="printPage('init-release-to-departments-application-outer', 'A4', 'P');"/>
    </div>--%>
</div>
<div id="init-release-to-departments-application-outer" class="form-outer">
    <s:if test="landApplication.workflowItem != null">
        <h2><s:property value="landApplication.workflowItem.workflowTask.nextAction"/></h2>
    </s:if>
    <s:if test="alienationType==@lk.icta.common.AppConstants@RELEASING_TO_DEPARTMENTS">
        <h2><s:label value="%{getText('detailed_releasing_to_department.label')}"/></h2>
    </s:if>
    <s:elseif test="alienationType==@lk.icta.common.AppConstants@VESTING_ORDER">
         <h2><s:label value="%{getText('detailed_vesting_order.label')}"/></h2>
    </s:elseif>

    <hr/>
    <s:form method="POST" id="gov-land-init-ReleseToDepartment-application-form"
            onsubmit="javascript:return (validateFormForInputDataSyntaxErrors('gov-land-init-ReleseToDepartment-application-form') && selectList())"
            enctype="multipart/form-data">
        <fieldset class="submit-date-fieldset-style">
            <table class="submited-date-table">
                <tr>
                    <td><s:label value="%{getText('submit_date.label')}" cssClass="mandatory-field"/><s:label
                            value="%{getText('date_format.label')}" cssClass="date-format"/></td>
                    <td><s:textfield id="submitDate" name="landApplication.submitDate"/></td>
                </tr>
                <tr>
                    <td><s:label value="Alienation Method" cssClass="mandatory-field"/></td>
                    <td>
                        <%--<s:if test="landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@LAND_ALLOCATION_APPROVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@ACCEPTED_AND_COMPLETED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED_AND_ARCHIVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@NOT_SUBMITTED_AND_ARCHIVED ||
                    landApplication.workflowItem.workflowTask == @lk.icta.core.entity.WorkflowTask@REJECTED">
                          <s:radio id="alienationMethodId" list="alienationMethodSet" name="alienationType"
                                 disabled="true"/>
                           <s:hidden name="alienationType"/>
                    </s:if>

                        <s:else>
                            <s:radio id="alienationMethodId" list="alienationMethodSet" name="alienationType"/>
                        </s:else>--%>
                    <s:radio id="alienationMethodId" list="alienationMethodSet" name="alienationType"/>

                    </td>
                </tr>
                    <%-- <tr>
                      <td><s:label value="%{getText('alienation_methods.label')}" cssClass="mandatory-field"/></td>
                      <td><s:checkboxlist list="alienationMethodSet" name="alienationMethodSelectedList"
                                          value="amSelectedList" theme="checkbox-theme"/></td>
                  </tr>  --%>
            </table>
            <table class="width-100">
                <tr>
                    <td><s:label value="%{getText('purpose_of_the_requesting_land')}"/></td>
                    <td colspan="3"><s:textarea cssClass="width-610-px" name="landApplication.purpose"
                                                id="purposeId"/></td>
                </tr>
            </table>
        </fieldset>
        <div id="tabs">
            <ul>
                <li><s:a href="#departmentDetails"><s:label
                        value="%{getText('details_of_department.label')}"/></s:a></li>
                <li><s:a href="#landAlienationDetails"><s:label value="%{getText('details_of_land.label')}"/></s:a></li>

            </ul>


            <div class="fieldset-style" id="departmentDetails">

                <table class="width-100" id="division">
                    <s:if test="viewMode">
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:textfield id="districtId" name="districtName" cssClass="width-200-px"
                                             disabled="true"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:textfield id="dsDivisionId" name="dsDivisionName" cssClass="width-200-px"
                                             disabled="true"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                <s:textfield id="gnDivisionId" name="holder.gnDivision.name" cssClass="width-200-px"/>
                            </td>
                        </tr>
                    </s:if>
                    <s:else>
                        <tr>
                            <td><s:label value="%{getText('district.label')}"/></td>
                            <td><s:select id="districtId" name="districtId" list="districtListAll"
                                          onchange="getDsDivisionByDistrict()" headerKey="0" headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/></td>
                            <td><s:label value="%{getText('ds_division.label')}"/></td>
                            <td><s:select id="dsDivisionId" name="dsDivisionId" list="dsDivisionList"
                                          onchange="getGnDivisionByDsDivision()" headerKey="0"
                                          headerValue="%{getText('select.label')}"
                                          cssClass="width-200-px"/></td>
                        </tr>
                        <tr>
                            <td><s:label value="%{getText('gn_division.label')}"/><span class="mandatory-field"></span>
                            </td>
                            <td>
                                <s:select id="gnDivisionId" name="holder.gnDivision.id" list="gnDivisionList"
                                          headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/>
                            </td>
                        </tr>
                    </s:else>
                </table>

                <table class="width-100">
                    <tr>
                        <td colspan="4">
                            <s:include value="../instituteDetails.jsp"/>
                        </td>
                    </tr>
                </table>
            </div>
            <div style="page-break-after:always;"></div>
            <div class="fieldset-style" id="landAlienationDetails">
                <table class="width-100">
                    <s:include value="../landAlienationDetails.jsp"/>
                </table>
            </div>

            <table>
                <tr>
                    <td align="left-align"><s:include value="../../documentUploadTemp.jsp"/></td>
                </tr>
            </table>
        </div>
        <hr/>
        <s:include value="buttons.jsp"/>
    </s:form>

</div>
<div id="landDetails" style="width: 780px;">
</div>
<s:hidden id="edit_mode" name="editMode"/>
<s:hidden id="pls_enter_department_name" value="%{getText('pls_enter_department_name')}"/>
<s:hidden id="pls_enter_submit_date" value="%{getText('pls_enter_submit_date')}"/>
<s:hidden id="pls_enter_department_address" value="%{getText('pls_enter_department_address')}"/>
<s:hidden id="pls_enter_contact_person" value="%{getText('pls_enter_contact_person')}"/>
<s:hidden id="pls_select_gnDivision" value="%{getText('pls_select_gnDivision.label')}"/>
<s:hidden id="select" value="%{getText('select.label')}"/>